package com.usian.admin.config;

import com.usian.admin.feign.WemediaFeign;
import com.usian.admin.service.WemediaNewsAutoScanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import groovy.util.logging.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Log4j2
public class WeMediaNewsAutoScanJob {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @Autowired
    private WemediaFeign wemediaFeign;

    /**
     * 每天0点执行一次
     *
     * @param param
     * @return
     * @throws Exception
     */
    @XxlJob("wemediaAutoScanJob03")
    public ReturnT<String> hello(String param) throws Exception {
        try {
            List<Integer> releaseIdList = wemediaFeign.findRelease();
            if (null != releaseIdList && !releaseIdList.isEmpty()) {
                for (Integer id : releaseIdList) {
                    wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ReturnT.SUCCESS;
    }
}
